package com.senken.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.senken.controller.LoginController;
import com.senken.entity.SkWo;
import com.senken.service.ISkWoService;



public class CreateWo {
	private static final Logger LOGGER = LogManager.getLogger(CreateWo.class);
	
	public  static String Createwo(ISkWoService service){
		LOGGER.info("创建工单号");
		Date date = new Date();
		SkWo old = service.find();
		System.out.println(old.getTime());
		SimpleDateFormat sdf  = new SimpleDateFormat("yyyyMMdd");
		if(sdf.format(date).equals(sdf.format(old.getTime()))){
			SimpleDateFormat sd  = new SimpleDateFormat("HHmmss");
			String c = old.getConuts();
			StringBuilder sb = new StringBuilder(c);
			sb.replace(8, 14, sd.format(date));
			long t = Long.parseLong(sb+"");
			t++;
			old.setTime(date);
			old.setConuts(t+"");
			service.updateWo(old);
			return t+"";
		}else{
			SimpleDateFormat s = new SimpleDateFormat("yyyyMMddHHmmss");
			String t = s.format(date);
			old.setConuts(t+"001");
			old.setTime(date);
			service.updateWo(old);
			return t+"001";
		}
	}
	
}
